//******************************************************************************
//this code is protected by the GNU affero GPLv3
//author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com>
//                        <digital.ragnarok AT gmail dot com>
//******************************************************************************
#include "globals.h"

static s8 create_surface(struct client *c,struct msg *m)
{
  s8 r;
  if(m->req_dws<3){
    PERR("client(%d):fatal:compositor::create_surface missing surface_id\n",
                                                                         c->so);
    r=LWL_ERR;goto exit;
  }

  LOG_WIRE("client(%d):compositor::create_surface surface_id=%u\n",c->so,
                                                                     m->req[2]);

  r=compositor_create_surface(c,m->req[2]);
exit:
  return r;
}

static s8 create_region(struct client *c,struct msg *m)
{
  s8 r;
  if(m->req_dws<3){
    PERR("client(%d):fatal:compositor::create_region missing region_id\n"
                                                                        ,c->so);
    r=LWL_ERR;goto exit;
  }

  LOG_WIRE("client(%d):compositor::create_region region_id=%u\n",c->so,
                                                                     m->req[2]);

  r=compositor_create_region(c,m->req[2]);
exit:
  return r;
}

s8 wl_compositor_req(struct client *c,struct msg *m)
{
  s8 r;
  switch(m->req_op){
  case WL_COMPOSITOR_CREATE_SURFACE:
    r=create_surface(c,m);
    break;
  case WL_COMPOSITOR_CREATE_REGION:
    r=create_region(c,m);
    break;
  default:
    PERR("client(%d):fatal:compositor unknown opcode %u)\n",c->so,m->req_op);
    r=LWL_ERR;
  };
  return r;
}
